package com.android.music.prolyric;

import java.util.ArrayList;
import java.util.HashMap;

import com.android.music.prolyric.database.DatabaseManger;
import com.android.music.prolyric.songmanager.Song;
import com.android.music.prolyric.songmanager.SongsManager;



import android.app.Activity;
import android.app.Fragment;
import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.SimpleAdapter;

import android.widget.ListView;

public class LibraryAllSong extends Activity{
	
	private SongsManager songManager ; 
	
	private ListView lvsongList; 
	private ArrayList<HashMap<String, String>> songs;
	int colorSong,colorSinger,colorTime;
	int defaultColor = 0xffffffff;
	private SharedPreferences prefs;
	private SimpleAdapterLib adapter;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.song_list);
		
		prefs = getSharedPreferences("libraryColor", MODE_PRIVATE);
		setColor();
		songManager = new SongsManager(this);
		lvsongList = (ListView)findViewById(R.id.lvSong);
		songs = songManager.getAllSong();

		 adapter = new SimpleAdapterLib(this, songs, R.layout.song_list_row, new String[]{"title","artist","duration"}, new int[]{R.id.tvsongtitle,R.id.tvsongartist,R.id.tvsongduration},colorSong,colorSinger,colorTime);
		 lvsongList.setAdapter(adapter);
		 lvsongList.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				GlobalState globle = (GlobalState) getApplication();
				globle.setGlobalSongs(songs);
				globle.setSongIndex(arg2);
				if(getParent()==null)
					setResult(Activity.RESULT_OK);
				else 
					getParent().setResult(Activity.RESULT_OK);
				finish();
				
			}
		});
		 
		 
	}
	
	private void setColor()
	{
		colorSong= (int) prefs.getInt("songcolor",defaultColor);
		colorSinger= (int) prefs.getInt("singercolor",defaultColor);
		colorTime=(int) prefs.getInt("timecolor",defaultColor);		
	}	  
	
}


